CREATE TABLE ##Temp_6d3cdaea_68e7_4a08_b42d_28e89e055636 (listId uniqueidentifier)

INSERT ##Temp_6d3cdaea_68e7_4a08_b42d_28e89e055636 (listId)


select [Lists].[tp_ID] from [Lists] WITH (NOLOCK) where ([tp_Title] = 'TypedList' and tp_Flags & 0x100 = 0x0 and [tp_WebId] in 
(SELECT Id
		FROM Webs
		WHERE (FullUrl LIKE '' + '%') OR (FullUrl LIKE '')))



SELECT tp_Fields
FROM ALlLists
WHERE tp_ID in (SELECT TOP(1) listId FROM ##Temp_6d3cdaea_68e7_4a08_b42d_28e89e055636)


SELECT   [datetime1],
         [float1],
         [_ListTitle],
         [_ListUrl],
         [_SiteUrl],
         [_SiteTitle],
         [_ItemID],
         [_WebID],
         [_ListID]
FROM     (SELECT [UserData].[datetime1],
                 [UserData].[float1],
                 [AllLists].[tp_Title]      [_ListTitle],
                 N'/' + UserData.tp_DirName [_ListUrl],
                 N'/' + Webs.FullUrl        [_SiteUrl],
                 [Webs].[Title]             [_SiteTitle],
                 [UserData].[tp_ID]         [_ItemID],
                 [Webs].[Id]                [_WebID],
                 [AllLists].[tp_ID]         [_ListID]
          FROM   [UserData] WITH (NOLOCK)
                 INNER JOIN [Docs] WITH (NOLOCK)
                   ON ([UserData].[tp_SiteId] = [Docs].[SiteId]
                       AND [UserData].[tp_DirName] = [Docs].[DirName]
                       AND [UserData].[tp_LeafName] = [Docs].[LeafName]
                       AND [UserData].[tp_Level] = [Docs].[Level])
                 INNER JOIN [AllLists] WITH (NOLOCK)
                   ON ([UserData].[tp_ListId] = [AllLists].[tp_ID])
                 INNER JOIN [Webs] WITH (NOLOCK)
                   ON ([AllLists].[tp_WebId] = [Webs].[Id])
          WHERE  ([UserData].[tp_RowOrdinal] = 0
                  AND [UserData].[tp_ListId] IN (SELECT listId
                                                 FROM   ##Temp_6d3cdaea_68e7_4a08_b42d_28e89e055636)
					AND (dateadd(dd,0, datediff(dd,0,[datetime1])) <= dateadd(dd,0, datediff(dd,0,'2007-12-04 21:00:00.000')))
)) [UserData]
ORDER BY [float1] ASC,
         [datetime1] ASC